package org.jackysoft.util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class FileDownload {
	private String title;
	private String realPath;
	private String fileType;
	private InputStream inputStream;

	public FileDownload(String title, String realPath, String fileType, InputStream data) {
		this.title = title;
		this.realPath = realPath;
		this.inputStream = data;
		this.fileType = fileType;
	}

	public FileDownload() {
	}

	public FileDownload(String title, String realPath) {
		this.title = title;
		this.realPath = realPath;
	}

	public String getName() {
		return title;
	}

	public String getTitle() {
		return StringUtils.toDownloadFileName(title);
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getRealPath() {
		return realPath;
	}

	public void setRealPath(String realPath) {
		this.realPath = realPath;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.SHORT_PREFIX_STYLE);
	}
	

	public String getFileType() {
		return fileType;
	}

	public int getDataSize() throws IOException {		
		if(inputStream==null)return 0;
		return getInputStream().available();
	}
	
	public String getMime(){
		return HttpUtil.extToMimeType(getFileType());
	}

	public void setFileType(String fileType) {
		this.fileType = fileType;
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}
}
